﻿// CWndAddGame.cpp: 实现文件
//

#include "pch.h"
#include "GameHacker.h"
#include "CWndAddGame.h"
#include "afxdialogex.h"
#include "CWndINJ.h"


// CWndAddGame 对话框

IMPLEMENT_DYNAMIC(CWndAddGame, CDialogEx)

CWndAddGame::CWndAddGame(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_ADDGAME, pParent)
	, m_pStrGameName(_T(""))
	, m_pStrGameFile(_T(""))
	, m_pStrGamePath(_T(""))
	, m_pStrGameMod(_T(""))
	, m_pStrGameCmd(_T(""))
{

}

CWndAddGame::~CWndAddGame()
{
}

void CWndAddGame::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_pStrGameName);
	DDX_Text(pDX, IDC_EDIT2, m_pStrGameFile);
	DDX_Text(pDX, IDC_EDIT3, m_pStrGamePath);
	DDX_Text(pDX, IDC_EDIT4, m_pStrGameMod);
	DDX_Text(pDX, IDC_EDIT5, m_pStrGameCmd);
}


BEGIN_MESSAGE_MAP(CWndAddGame, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CWndAddGame::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON4, &CWndAddGame::OnBnClickedButton4)
	ON_BN_CLICKED(IDOK, &CWndAddGame::OnBnClickedOk)
END_MESSAGE_MAP()


// CWndAddGame 消息处理程序


void CWndAddGame::SetData(CString& GameName, CString& GameFile, CString& GamePath, CString& GameCmd, CString& GameMod)
{
	m_pStrGameName = GameName;
	m_pStrGameFile = GameFile;
	m_pStrGamePath = GamePath;
	m_pStrGameMod = GameCmd;
	m_pStrGameCmd = GameMod;

	UpdateData(FALSE);
}

void CWndAddGame::OnBnClickedButton1()
{
	UpdateData(true);
	TCHAR szFilter[] = _T("exe (*.exe)|*.exe|dat (*.dat)|*.dat|");
	CFileDialog dialog(true, NULL, NULL, 6, szFilter, this);
	if (dialog.DoModal() == IDOK) {
		m_pStrGameName = dialog.GetFileTitle();
		m_pStrGameFile = dialog.GetPathName();
		m_pStrGamePath = dialog.GetFolderPath() + L"\\";
		UpdateData(false);
	}
}


void CWndAddGame::OnBnClickedButton4()
{
	UpdateData(true);
	TCHAR szFilter[] = _T("动态链接库 (*.dll)|*.dll|");
	CFileDialog dialog(true, NULL, NULL, 6, szFilter, this);
	if (dialog.DoModal() == IDOK) {
		m_pStrGameMod = dialog.GetPathName();
		UpdateData(false);
	}
}


void CWndAddGame::OnBnClickedOk()
{
	UpdateData(TRUE);
	CWndINJ* lpParent = (CWndINJ*)m_lpParent;
	if (m_bCreate) {
		lpParent->AddGame(m_pStrGameName, m_pStrGameFile, m_pStrGamePath, m_pStrGameCmd, m_pStrGameMod);
	}
	else {
		lpParent->SaveGame(m_pStrGameName, m_pStrGameFile, m_pStrGamePath, m_pStrGameCmd, m_pStrGameMod, m_nIndex);
	}

	CDialogEx::OnOK();
}

void CWndAddGame::Init(void* father, BOOL bCreate, int nIndex)
{
	m_lpParent = father;
	m_bCreate = bCreate;
	m_nIndex = nIndex;
}
